const api = require('../../../utils/api') // 引入API
const {myRequest} = require('../../../utils/myRequest') // 请求函数
Page({
  data: {
    categoryList: [], // 左边栏
    subCategoryList: [], // 右边栏数据
    id: 1005000  // 初始渲染第一栏数据
  },
  onLoad: function (options) {
    this.contentData(this.data.id)
    myRequest({
      url: api.catalogIndex,
      success: res => {
        let categoryList = res.data.data.categoryList
        this.setData({
          categoryList: categoryList
        })
      }
    })
  },
  // 右边栏数据
  contentData(id) {
    myRequest({
      url: api.catalogCurrent,
      data: {
          id: id
      },
      success: res => {
        let subCategoryList = res.data.data.currentCategory.subCategoryList        
        this.setData({
          subCategoryList: subCategoryList                
        })
      }
    })
  },
  // 点击切换
  selectItem(e){
    let id = e.currentTarget.dataset.id;
    this.setData({
      id: id
    })
    this.contentData(id)
  },
  // 跳转到商品列表
  toGoodsList(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `../../subPages/goodsList/goodsList?id=${id}`
    });
  },
  onReachBottom: function () {

  },
})